package native

import (
	"jvm/nzpJvm/runtime_area"
)

// 注册本地方法

type NativeMethod func(frame *runtime_area.Frame)

var registry = map[string]NativeMethod{}

func Register(className, methodName, methodDesc string,method NativeMethod)  {
	key := className+"~"+methodName+"~"+methodDesc
	registry[key] = method
}

func emptyNativeMethod(frame *runtime_area.Frame)  {
    // do nothing
}

func FindNativeMethod(className, methodName, methodDesc string) NativeMethod {
	key := className+"~"+methodName+"~"+methodDesc
	if method, ok := registry[key]; ok {
		return method
	}
	if methodDesc == "()V" && methodName == "registerNatives" {
		return emptyNativeMethod
	}
	return nil
}